<?php
namespace app\common\command;


use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Env;
use think\facade\Log;

class Redis extends Command
{
    protected function configure()
    {
        $this->setName('redis')
            ->setDescription('redis监听');
    }
    protected function execute(Input $input, Output $output)
    {
        // 定义不超时 一直运行
        ini_set('default_socket_timeout', -1);
        $redis = new \Redis();
        $redis->connect(Env::get('redis.host'),Env::get('redis.port'));
        $redis->auth(Env::get('redis.password'));
        $redis->psubscribe(["__keyevent@0__:expired"], function($rediss, $pattern, $chan, $msg) use($output) {
            try {
                Log::record("{$msg}你失效了");
                //处理业务逻辑
                $output->writeln("Hello,{$msg}你失效了");

            } catch (\Exception $e) {
                
            }
        });
    }
}